package org.gunncs.actors;
import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.peripheral.LEDColor;
import com.sun.spot.sensorboard.peripheral.ITriColorLED;
import org.gunncs.actoriface.Actor;
import org.gunncs.actoriface.BeaconSensor;
import org.gunncs.actoriface.Robot;
import org.gunncs.actoriface.Sensor;
/**
 * <<Class summary>>
 *
 * @author Anand Gupta &lt;&gt;
 * @version $Rev$
 */
public class BeaconActor implements Actor{
  
	boolean targetLeft;
	boolean targetRight;
	boolean locked;
	ITriColorLED overallStatus = EDemoBoard.getInstance().getLEDs()[4];
	public BeaconActor(){
	  targetLeft = false;
	  targetRight = false;
	  locked = false;
	}
	
	public void act(Robot r){
	  System.out.println(this +" thinking");
	  if(!targetLeft && !targetRight){
	    if(locked){
	      r.stop();
	      locked = false;
        overallStatus.setOff();
	    }
	    return;
	  }else{
	    r.driveDirect((targetLeft? 350: 100), (targetRight? 350: 100));
	    overallStatus.setRGB((targetLeft? 190 : 0),(targetRight? 190: 0),0);
      overallStatus.setOn();
	    locked = true;
	  }
	  
	}
	
	public void updateSensors(Sensor[] sensors){
	  targetLeft = (sensors[6].getState()[BeaconSensor.REDBUOY] == BeaconSensor.PRESENT);
  	targetRight = (sensors[6].getState()[BeaconSensor.GREENBUOY] == BeaconSensor.PRESENT);
	}
	
}
